/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/* Chung Nguyen Huu
 * own comment
 * 2011/09/10
 */
$(document).ready(function(){
    
    $search_url = $("#global_url").attr("value") + "/index.php?act=regportal&CODE="; 
    //load du lieu search
    $.post( 
        $search_url + "load-all-member",
        null,
        function(data){
            //su ly du lieu tra ve de search
            if(data != null){
                members = data.split("[$$$$$]");
                $("#txtsearch").autocomplete(members, {
                    minLength: 0,
                    focus: function( event, ui ) {				
			$( "#txtsearch" ).val( ui.item);				
			return false;			
                    },
                    select: function( event, ui ) {				
			$( "#project" ).val( ui.item);				
			$( "#project-id" ).val( ui.item);				
			$( "#project-description" ).html( ui.item);				
			$( "#project-icon" ).attr( "src", "images/" + ui.item);				
			return false;			
                    }		
                    //multiple: true,
                    //autoFill : true
                    //selectFirst : true
                    
                });
            }
        }
    );

    //key enter
    //
    
    $("#txtsearch").keyup(function(e){
        e.preventDefault();
        if(e.keyCode == 13){
            $.post( 
                $search_url + "search-friends",
                {txtsearch:htmlspecialchars($("#txtsearch").val(),['ENT_NOQUOTES', 'ENT_QUOTES'])},
                function(data) {
                    if(data != ""){
                        $("#content").html(data);                    
                        $("#search-key").empty().html($("#txtsearch").attr("value"));
                        $(".currentPage").empty().html(list_friend_title);
                    }
                },
                'html'
            );
        }
        return false;
    });
    
});
(function(){
    members = null;
    $.fn.search_friends = function(){
        $('#btsearch').click(function(){
            //console.log($search_url = $("#search_url").attr("value") + "act=regportal&CODE=");
            $.post( 
                $search_url + "search-friends",
                {txtsearch:htmlspecialchars($("#txtsearch").val(),['ENT_NOQUOTES', 'ENT_QUOTES'])},
                function(data) {
                    if(data != ""){
                        $("#content").html(data);                    
                        $("#search-key").empty().html($("#txtsearch").attr("value"));
                        $(".currentPage").empty().html(list_friend_title);
                    }
                },
                'html'
            );
        });
    }
    $.fn.search_paging = function(){  
        $('.paging').find('a').each(function(index){
            $(this).click(function(){
                var url = $(this).attr('href');
                var st = 0;
                values = url.split("&");
                if(values[2] != null){
                    temps = values[2].split("=");
                    st = temps[1];
                }
                $.post( 
                    $search_url + "search-friends",   
                    {txtsearch:values[1], st:st},
                    function(data) {
                        if($.trim(data) != ""){
                            $("#content").html(data);                    
                            $("#search-key").empty().html($("#txtsearch").attr("value"));
                        }
                    },
                    'html'
                );
                return false;
            });
        });
    }
    $.fn.diaries_paging = function(){
        
        $('.paging').find('a').each(function(){
            $(this).click(function(){
                
                var url = $(this).attr('href');
                //console.log(url);
                var st = 0;
                values = url.split("&");
                //console.log(values);return false;
                if(values[1] != null){
                    temps = values[1].split("=");
                    st = temps[1];
                }
                window.location.href=$("#global_url").attr("value") + "act=diary&st=" + st;
                $.post( 
                    $("#global_url").attr("value") + "act=diary",
                    {st:st},
                    function(data) {
                        if($.trim(data) != ""){
                            //console.log(data);
                            $("#content").html($.trim(data));                    
                        }
                    },
                    'html'
                );
                return false;
            })
        });
    }
})(jQuery);
function htmlEntities(str) {
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}